<template>
    <div class="box">
        <div class="title">任务列表</div>
        <div class="list">
            <div class="task" v-for="(item,index) in $store.state.taskList" :key="index" :class="{ unfinished: item.status==false }" >
                <div>
                    <span><input type="checkbox" :checked="item.status" @click="handleClick(item)"></span>
                    <span>{{item.id}}</span>
                    <span>{{item.name}}</span>
                </div>
                <span @click="clear(index)">删除</span>
            </div>
            <!-- 当taskList的长度为0时，渲染 -->
            <div v-show=" $store.state.taskList.length == 0" class="empty">任务列表为空,请添加一个任务!</div>
        </div>
    </div>
</template>

<script>
export default {
    methods:{
        // 改变任务状态
        handleClick(item){
            this.$store.commit('changeStatus',item)
        },
        clear(index){
           this.$store.commit('deleteTask',index)
        }
    }
}
</script>

<style lang='scss' scoped>
.box .title{
    font-weight: bold;
    line-height: 40px;
}
.box .list .task{
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 10px;
    margin: 10px 0;
    background-color: lightseagreen;
    line-height: 40px;
}
.box .list .task.unfinished{
    background-color: red;
}
.box .list .task span{
    display: inline-block;
    margin-right: 10px;
}
.empty{
    text-align: center;
    padding: 50px 0;
}
</style>